-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[tb_ObtenerPermiso]
(
	@pID_Usuario INT,
	@pFormulario varchar(200),	
	@pID_Accion INT,
	@pPermisoCorrecto BIT OUT
)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	--
	SELECT  @pPermisoCorrecto = CAST(1 AS BIT)
	FROM    Usuario INNER JOIN
			Usuario_Grupo ON Usuario.ID_Usuario = Usuario_Grupo.ID_Usuario INNER JOIN
			Grupo_Permiso ON Usuario_Grupo.ID_Grupo = Grupo_Permiso.ID_Grupo INNER JOIN
			Permiso ON Grupo_Permiso.ID_Permiso = Permiso.ID_Permiso INNER JOIN
			Permiso_Accion ON Permiso.ID_Permiso = Permiso_Accion.ID_Permiso INNER JOIN
			Accion ON Permiso_Accion.ID_Accion = Accion.ID_Accion INNER JOIN
			Formulario ON Permiso.ID_Formulario = Formulario.ID_Formulario
	WHERE	Usuario.ID_Usuario = @pID_Usuario AND 
			Formulario.Nombre = @pFormulario AND 
			Accion.ID_Accion = @pID_Accion
	--
	IF @pPermisoCorrecto IS NULL
		SET @pPermisoCorrecto = CAST(0 AS BIT);
	--
END
GO
